﻿##此DEMO的功能：查询手机类的淘客商品
# -*- coding: utf-8 -*-
import urllib, urllib2, string, time, md5, re, types, logging

#获得当前时间
t = time.localtime()

#参数数组
paramArray = {
	'app_key':'12022540',
	'method':'taobao.trades.sold.get',
	'format':'json',
	'v':'2.0',
	'timestamp':time.strftime('%Y-%m-%d %X', t),
	
	'fields':'buyer_nick, created, price, status, num, receiver_name, receiver_state, receiver_city, receiver_district, receiver_address, receiver_mobile,',
	
	'start_created': '2010-06-27 21:00:00',
	'end_created':'2010-06-28 00:00:00',
	
	#'session':'19219b2d98bbf25e46e844f762f731ff38098',
  
}

#签名函数
def _sign(param,sercetCode):
	src = sercetCode + ''.join(["%s%s" % (k, v) for k, v in sorted(param.items())])
	return md5.new(src).hexdigest().upper()
	

#生成签名
sign = _sign(paramArray, '6f7a04f813d9a9fc916e0b15854e9f6f')
paramArray['sign'] = sign

#组装参数
form_data = urllib.urlencode(paramArray)

#访问服务
urlopen = urllib2.urlopen('http://gw.api.taobao.com/router/rest', form_data)

rsp = urlopen.read()
rsp = rsp.decode('UTF-8')

print rsp
print 

import simplejson as json

rsp = json.loads(rsp)
print rsp['trades_sold_get_response']['total_results']


